﻿using System;
using System.Web.Mvc;
using Less.SRV;
using LessBoard.Models;
using Less.Core;

namespace LessBoard.Controllers
{
    public class LogController : Controller
    {
        //
        // GET: /Log/

        public ActionResult Index()
        {
            try
            {
                var model = new LogModel();
                return View(model);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return new EmptyResult();
            }
        }


        public ActionResult Severities()
        {
            try
            {
                var model = new SeveritiesModel();
                var srv = new LogSRV("auditConnection");
                model.LogEntriesBySeveritySummary = srv.GetLogEntriesBySeveritySummary();
                return View(model);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return new EmptyResult();
            }
        }
        //http://localhost:49838/Log/EntriesOfSeverity?severityOfEntries=Error
        public ActionResult EntriesOfSeverity(string severityOfEntries)
        {
            try
            {
                if (severityOfEntries == null) throw new ArgumentNullException("severityOfEntries");
                EntrySeverities severiry = EntrySeverities.Error;
                if (!Enum.TryParse(severityOfEntries, out severiry)) throw new ArgumentException("Value not valid");
                var model = new EntriesOfSeverityModel();
                model.SeverityOfEntries = severiry;
                var srv = new LogSRV("auditConnection");
                model.LogEntriesOfSeverity = srv.GetBySeverity(severiry);
                return PartialView(model);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return new EmptyResult();
            }
        }
    }
}
